package com.erp.module.faHuoDanJu.faHuo1

import android.content.Context
import com.erp.bean.DanjuBean
import com.erp.Interface.OnUserDataInterface
import com.erp.module.faHuoDanJu.AddFaHuoModel
import com.erp.module.faHuoDanJu.FaHuoDanJuContract
import com.erp.pull.BasePullP
import com.erp.util.JsonUtil
import org.json.JSONArray
import org.json.JSONException
import org.json.JSONObject
import java.util.*

/**
 * Created by Administrator on 2019/3/19/019.
 * 作者：刘洋
 */
class IMyFaHuoP(val context: Context, val KView: FaHuoDanJuContract.MyFaHuoView, val list: MutableList<DanjuBean>,val type :Int) : BasePullP(), FaHuoDanJuContract.MyFaHuoP {

    val modle : FaHuoDanJuContract.FaHuoMP= AddFaHuoModel()
    var zhuanmaidian =""
    var baohao =""
    init {
        PullV =KView
    }

    override fun getData(page: Int, pagesize: Int, onUserDataInterface: OnUserDataInterface) {
        modle.getdanju(type, context, page, pagesize, zhuanmaidian, baohao,onUserDataInterface)
    }

    override fun jsondata(data: String?) {
        if(data==null){
            return
        }
        try {
            val js = JSONArray(data)
            for (i in 0 until js.length()) {
                val danjuBean = DanjuBean()
                val jo = js.get(i) as JSONObject
                danjuBean.uri = JsonUtil.getvolue(jo, "uri")
                danjuBean.ctime = JsonUtil.getvolue(jo, "ctime")
                danjuBean.fid = JsonUtil.getvolue(jo, "fid")
                danjuBean.creator_name = JsonUtil.getvolue(jo, "creator_name")
                val onumsBeanList = ArrayList<DanjuBean.OnumsBean>()
                val jsonum = JsonUtil.getjsvolue(jo, "onums")
                if (jsonum != null) {
                    for (j in 0 until jsonum.length()) {
                        val onumsBean = DanjuBean.OnumsBean()
                        val joonum = jsonum.get(j) as JSONObject
                        onumsBean.oid = JsonUtil.getvolue(joonum, "oid")
                        onumsBean.onum = JsonUtil.getvolue(joonum, "onum")
                        onumsBean.shop_name = JsonUtil.getvolue(joonum, "shop_name")
                        onumsBeanList.add(onumsBean)
                    }
                }
                danjuBean.onums = onumsBeanList
                list.add(danjuBean)
            }
        } catch (e: JSONException) {
            e.printStackTrace()
        }

    }

    override fun listClean() {
        list.clear()
    }

    override fun sousuo(zhuanmaidian: String, baohao: String) {
        this.zhuanmaidian=zhuanmaidian
        this.baohao=baohao
        xiala()
    }


}